<?php

/**
 * 前台举报控制器
 */
class PunishController extends FrontBaseC {

    //特殊的控制器方法
    public function actions() {
        return array(
            //验证码
            'captcha' => array(
                'class' => 'CCaptchaAction',
                'transparent' => true, //是否使用透明背景
                'maxLength' => 6, // 最多生成几个字符
                'minLength' => 4, // 最少生成几个字符
            ),
        );
    }

    public function actionIndex() {
        $objModel = new PunishModel('add');

        $good_id = isset($_GET['good_id']) ? $_GET['good_id'] : '';
        $objGoodsModel = GoodsModel::model()->findByPk($good_id);
        if (!$objGoodsModel) {
            $this->error('访问错误', $this->createUrl('/'));
        }
        if (IS_POST) {
            $code = Yii::app()->request->getParam('code');
            if (empty($code) || !$this->createAction('captcha')->validate($code, false)) {
                $this->error('验证码错误');
            }
            $bloSave = $objModel->editor($_POST, $objGoodsModel);
            if ($bloSave) {
                //通知对应的后台管理人员
                $extendParams = array(
                    'title' => '有用户举报(' . $objGoodsModel->goods_name . ')商品违规！',
                    'content' => '有用户举报(' . $objGoodsModel->goods_name . ')商品违规！请及时处理！',
                );
                $notice_punish = (int) ConfigModel::model()->getConfig('notice_punish');
                if ($notice_punish) {
                    AdminMessage::model()->notice($notice_punish, false, AdminMessage::punish, $extendParams);
                }
                $this->success('提交成功,我们会尽快确认', self::U('/index'));
            } else {
                $this->error($objModel->getOneError());
            }
        }
		$this->description = '';
		$this->keywords = '';
		$this->title = $objGoodsModel->goods_name.'【商品举报】';
        $this->render('index', array('model' => $objModel, 'goodModel' => $objGoodsModel));
    }

}
